package com.chinasofti.nio;

import java.nio.ByteBuffer;

public class ByteBufferDemo {
    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
        //position()   当前要操作的索引
        //limit()       最多能操作到那个索引
        //capacity()    缓冲区的总长度
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.limit());
//        System.out.println(byteBuffer.capacity());

        //put(byte b)一次添加一个字节
        //byteBuffer.put((byte)97);
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.limit());
//        System.out.println(byteBuffer.capacity());

        //添加一个字节数组
//        byteBuffer.put("aaa".getBytes());
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.limit());
//        System.out.println(byteBuffer.capacity());

        //修改position
//        byteBuffer.position(1);
//        System.out.println(byteBuffer.position());

        //修改limit
        //byteBuffer.limit(3);
//        System.out.println(byteBuffer.position());
//        System.out.println(byteBuffer.limit());
//        System.out.println(byteBuffer.capacity());
        //是否能操作
        //System.out.println(byteBuffer.hasRemaining());
        //还有多少能操作
        //System.out.println(byteBuffer.remaining());

        byteBuffer.put("0123456789".getBytes());
        System.out.println(byteBuffer.remaining());
        System.out.println(byteBuffer.hasRemaining());
    }
}
